package net.luvina.manageuser.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.model.SelectItem;

public class ListCalendarManager {
    private static final int TOTAL_MONTH_IN_YEAR = 12;
    private static final int TOTAL_DAY_IN_MONTH = 31;
    private static final int FROM_YEAR = 1900;

    public static List<SelectItem> getListSelectItemDay() {
        List<SelectItem> listSelectItemDay = new ArrayList<SelectItem>();
        for (int day = 1; day <= TOTAL_DAY_IN_MONTH; day++) {
            listSelectItemDay.add(new SelectItem(Integer.toString(day), Integer
                    .toString(day)));
        }
        return listSelectItemDay;
    }

    public static List<SelectItem> getListSelectItemMonth() {
        List<SelectItem> listSelectItemMonth = new ArrayList<SelectItem>();
        for (int month = 1; month <= TOTAL_MONTH_IN_YEAR; month++) {
            listSelectItemMonth.add(new SelectItem(Integer.toString(month),
                    Integer.toString(month)));
        }
        return listSelectItemMonth;
    }

    public static List<SelectItem> getListSelectItemYear() {
        int nowYear = getYearNow();
        List<SelectItem> listSelectItemYear = new ArrayList<SelectItem>();
        for (int year = FROM_YEAR; year <= nowYear; year++) {
            listSelectItemYear.add(new SelectItem(Integer.toString(year),
                    Integer.toString(year)));
        }
        return listSelectItemYear;
    }

    private static int getYearNow() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date = new Date();
        int year = Integer.parseInt(sdf.format(date));
        return year;
    }
}
